home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-10-26 | 1.9 KB | 74 lines | [TEXT/ScoM] |
- PROGRAMMING AUTOMATAS
-
- This makes interesting cellular automata sequences. This is the original
- from Common Music
-
- (defun automaton (p1 p2 p3)
- (let* ((w (- (- p3 p2))))
- (incf w (if (>= w 0) -12 12))
- (incf w p1)
- (cond ((< w 36)
- (+ w (* 12 (random 4)) 2))
- ((> w 98)
- (- w (* 12 (random 4)) -2))
- (t (1+ w)))))
-
- ; version modified by Paul Berg for a smaller range
- ; adapted to SCOM by Peter Stone
-
- (defun automaton (p1 p2 p3)
- (let (next)
- (setf next
- (let ((w (- (- p3 p2))))
- (incf w (if (>= w 0) -1 2))
- (incf w p1)
- (cond ((< w 36)
- (+ w (* 2 (get-random 0 4)) 2))
- ((> w 98)
- (- w (* 2 (get-random 0 4)) -2))
- (t (+ 1 w)))))
- (setf p3 p2)
- (setf p2 p1 )
- (setf p1 next)))
-
- ; run automaton n times with intial parameters p1 p2 p3
-
- (defun gen-automaton (seed n p1 p2 p3)
- (let ((result nil))
- (init-rnd seed)
- (dotimes (i n)
- (push (automaton p1 p2 p3) result))
- (nreverse result)))
-
- ; example
- ; (gen-automaton 0.2123 100 10 20 30)
-
- The one modified by Paul Berg died in 100 iterations. If you view this
- in visualizer you'll see it makes a bit high values, but you can
- rescale them with vector-scale, vector-round or vector-offset.
-
- ; run automaton n times with intial parameters p1 p2 p3
-
- (defun gen-automaton (seed n p1 p2 p3)
- (let (result next)
- (init-rnd seed)
- (dotimes (i n)
- (setq next
- (let ((w (- (- p3 p2))))
- (incf w (if (>= w 0) -12 12))
- (incf w p1)
- (cond ((< w 36)
- (+ w (* 12 (get-random 0 4)) 2))
- ((> w 98)
- (- w (* 12 (get-random 0 4)) -2))
- (t (1+ w)))))
- (setq p3 p2)
- (setq p2 p1)
- (setq p1 next)
- (push next result))
- (nreverse result)))
-
- ; example
- ; (gen-automaton 0.2123 100 10 20 30)
-
-